﻿@model IEnumerable<ETA.Entity.ReferrerLog>
@{
    ViewBag.Title = "积分兑换界面";
    var userName = "";
    var userId = "";
    if (ViewBag.User != null)
    {
        var user = (ETA.Entity.User)ViewBag.User;
        userName = user.UserName;
        userId = user.UserId;
    }

    int? pointTotal = 0;//获得积分总计 即推荐一人就有1000积分与是否出国无关
    int? unUsedPointTotal = 0;//已出国的实习生有关的数据 总分减去已兑换
    int? usedPointTotal = 0;//已兑换
}


<div class="mainContentWithBorderNopadding2">
    <div class="refferTitle">
        <table id="handlerRefferLogDetailTB">
            <tr>
                <td>
                    <label for="ReferrerId">快车之友ID:</label><span id="ReferrerId">@userId</span></td>
                <td>
                    <label for="Referrer">快车之友名称:</label><span id="Referrer">@userName</span></td>
                <td style="padding-left: 10px">
                    <button type="button" class="btn btn-primary" id="btnChange">兑换积分，打印清单</button></td>
            </tr>
            <tr>

                <td>
                    <label for="TotalPoint">获得积分总数:</label>
                    <span id="TotalPoint"></span></td>
                <td>
                    <label for="ChangedPoint">已兑换积分总数:</label><span id="ChangedPoint"></span></td>
                <td></td>
            </tr>

        </table>
    </div>
    <div>
        <table class="table table-bordered table-hover ExpandTB">
            <thead>
                <tr>
                    <td>被推荐人ID</td>
                    <td>被推荐人姓名</td>
                    <td>注册时间</td>
                    <td>出国时间</td>
                    <td>获得积分</td>
                    <td>已兑换</td>
                    <td>可兑换积分</td>
                    <td>兑换积分</td>
                </tr>
            </thead>
            <tbody>
                @foreach (var log in Model)
                {
                    var abroadDate = string.Empty;
                    var point = log.Point;
                    var usedPoint = log.UsedPoint;
                    int? unUsedPoint = 0;
                    var unUsedPointStr = string.Empty;
                    var registrationBind = log.Referrer.RegistrationBind;
                    if (registrationBind != null && registrationBind.IsDelete == false)
                    {
                        abroadDate = registrationBind.CreateDate.ToShortDateString();
                        unUsedPoint = point - (usedPoint.HasValue?usedPoint:0);
                        usedPointTotal += usedPoint;
                    }

                    unUsedPointStr = unUsedPoint == 0 ? "" : unUsedPoint.ToString();
                    pointTotal += point;
                    unUsedPointTotal += unUsedPoint;
                    <tr>
                        <td>@log.Referrer.UserId</td>
                        <td>@log.Referrer.UserName</td>
                        <td>@log.Referrer.CreateDate.ToShortDateString()</td>
                        <td>@abroadDate</td>
                        <td>@point</td>
                        @*总积分*@
                        <td>@usedPoint</td>@* 已兑换*@
                        <td>@unUsedPointStr</td>
                        @*可兑换*@
                        @if (unUsedPoint > 0)
                        { 
                            <td>
                                <input type="text" class="textChangePoint"  data-Max="@unUsedPoint" data-logId="@log.ReferrerLogId" /></td>
                        }
                        else
                        {
                            <td></td>
                        }


                    </tr>
                }
            </tbody>
            <tfoot>
                <tr>
                    <td>合计</td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td>@pointTotal</td>
                    <td>@usedPointTotal</td>
                    <td>@unUsedPointTotal</td>
                    <td></td>

                </tr>
            </tfoot>
        </table>
        <input type="hidden" id="hiddendpointTotal" value="@pointTotal"/>
        <input type="hidden" id="hiddendusedPointTotal" value="@usedPointTotal"/>
    </div>
</div>

@section scripts
{
    @Scripts.Render("~/bundles/JSTmp")
    @Scripts.Render("~/bundles/Page")
    @Scripts.Render("~/bundles/WdatePicker")
    @Scripts.Render("~/bundles/FinanceAdmin")
}

